﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using LPV_POS.Module;
using LPV_POS;
using LPV_POS.Baocao;
using LPV_POS.Baocao.Ellic;


public class Inbillkhachsan
{
    public void f_print_res_bill(string _MAPHIEU, bc_inbillkhachsan CrReport)
    {
        try
        {
            thuvien othuvien = new thuvien();
            DataSet ds_inbill_khachsan = othuvien.SP_SelectDataset("sp_inbill_khachhang",
                                                                    new string[] { "@MAPHIEU" },
                                                                    new object[] { _MAPHIEU });

            DataTable tbSo_Bao_Cao = othuvien.SP_SelectDataTable("sp_BH_PHIEU_SOBAOCAO", new string[] { "@MA_PHIEU" }, new object[] { _MAPHIEU });
            if (tbSo_Bao_Cao.Rows.Count > 0)
                CrReport.DataDefinition.FormulaFields["txt_so"].Text = "'" + tbSo_Bao_Cao.Rows[0][0] + "'";

            if (ds_inbill_khachsan.Tables != null)
            {
                #region "Tieu de bao cao"
                if (ds_inbill_khachsan.Tables[0].Rows.Count > 0)
                {
                    CrReport.DataDefinition.FormulaFields["txt_tencongty"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["TENKH"] + "'";
                    CrReport.DataDefinition.FormulaFields["txt_diachi"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["DIACHI"] + "'";
                    CrReport.DataDefinition.FormulaFields["txt_email"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["EMAIL"] + "'";
                    CrReport.DataDefinition.FormulaFields["txt_Fax"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["FAX"] + "'";
                    CrReport.DataDefinition.FormulaFields["txt_dienthoai"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["DIENTHOAI"] + "'";

                    CrReport.DataDefinition.FormulaFields["txt_masothue"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["MA_SO_THUE"] + "'";
                    CrReport.DataDefinition.FormulaFields["txt_tenkhachhang"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["NGUOILIENHE"] + "'";
                    CrReport.DataDefinition.FormulaFields["txt_sophong"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["SOPHONG"] + "'";
                    CrReport.DataDefinition.FormulaFields["txt_sohochieu"].Text = "'" + ds_inbill_khachsan.Tables[0].Rows[0]["CMND_HOCHIEU"] + "'";
                    //
                    float iCK_Tien = 0;
                    float iKM_TIEN = 0;
                    float iTTIEP_TIEN = 0;
                    float iPHU_THU = 0;
                    float iPHU_THU_KHAC = 0;
                    float iVAT_TIEN = 0;
                    float iTONG_TIEN = 0;
                    float iTienDatCoc = 0;
                    float iTienPhaiTra = 0;
                    //float iTienDaNhan = 0;

                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["CK_TIEN"] + "", out iCK_Tien);
                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["KM_TIEN"] + "", out iKM_TIEN);
                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["TTIEP_TIEN"] + "", out iTTIEP_TIEN);
                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["PHU_THU"] + "", out iPHU_THU);
                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["PHU_THU_KHAC"] + "", out iPHU_THU_KHAC);
                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["VAT_TIEN"] + "", out iVAT_TIEN);
                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["TONG_TIEN"] + "", out iTONG_TIEN);
                    float.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["TienDatCoc"] + "", out iTienDatCoc);
                    iTienPhaiTra = iTONG_TIEN - iTienDatCoc;

                    CrReport.DataDefinition.FormulaFields["pgiamgia"].Text = "'" + iCK_Tien.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pkhuyenmai"].Text = "'" + iKM_TIEN.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pTIP"].Text = "'" + iTTIEP_TIEN.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pSC"].Text = "'" + iPHU_THU.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pPhuThu"].Text = "'" + iPHU_THU_KHAC.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pVAT"].Text = "'" + iVAT_TIEN.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pTONG_TIEN"].Text = "'" + iTONG_TIEN.ToString("N0") + "'";
                    //
                    CrReport.DataDefinition.FormulaFields["pTienDatCoc"].Text = "'" + iTienDatCoc.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pTienPhaiTra"].Text = "'" + iTienPhaiTra.ToString("N0") + "'";
                    CrReport.DataDefinition.FormulaFields["pTienThoiLai"].Text = "'" + (iTienDatCoc - iTONG_TIEN).ToString("N0") + "'";

                    //NGUOILIENHE

                    int iTHANH_TIEN = 0;
                    int.TryParse(ds_inbill_khachsan.Tables[0].Rows[0]["THANH_TIEN"] + "", out iTHANH_TIEN);
                    CrReport.DataDefinition.FormulaFields["txt_THANH_TIEN"].Text = "'" + iTHANH_TIEN.ToString("N0") + "'";

                    string schangeNumericToWords1 = new cpublic().ChuyenSo_ThanhChu(iTONG_TIEN + "") + " đồng";
                    string schangeNumericToWords2 = new LPV_POS.manhinh.cls_convert_number_word().changeNumericToWords(iTONG_TIEN).ToLower().Trim() + " VND";

                    CrReport.DataDefinition.FormulaFields["txt_TIENBANGCHU"].Text = "'" + schangeNumericToWords1 + " (" + schangeNumericToWords2 + ")" + "'";
                }
                #endregion

                int iThucAn = ds_inbill_khachsan.Tables[2].Rows.Count;
                int iGiatUi = ds_inbill_khachsan.Tables[5].Rows.Count;
                //@NHOM_GIATUI - @NHOM_THUCAN
                if (iGiatUi - iThucAn > 2)
                    for (int ii = iThucAn; ii < iGiatUi; ii++)
                        ds_inbill_khachsan.Tables[2].Rows.Add(ds_inbill_khachsan.Tables[2].NewRow());

                //"Tien gio khach san"                
                //if (CrReport.Subreports["rptTiengio.rpt"]!=null)
                CrReport.Subreports["rptTiengio.rpt"].SetDataSource(ds_inbill_khachsan.Tables[1]);

                //--1.@NHOM_THUCAN
                CrReport.Subreports["rptCom.rpt"].SetDataSource(ds_inbill_khachsan.Tables[2]);                

                //--2.@NHOM_DIENTHOAI
                CrReport.Subreports["rptDienThoai.rpt"].SetDataSource(ds_inbill_khachsan.Tables[3]);                

                //--3.@NHOM_THUCUONG
                CrReport.Subreports["rptNuoc.rpt"].SetDataSource(ds_inbill_khachsan.Tables[4]);

                //--4.@NHOM_GIATUI
                CrReport.Subreports["rptGiatUi.rpt"].SetDataSource(ds_inbill_khachsan.Tables[5]);

                //

            }


        }
        catch (Exception ex)
        {
            MessageBox_LPV.Show("Thông báo\n" + ex.Message);
        }
    }
}

